package StudyCode.summary.mydatetime;

import java.time.*;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class UsingZonedDateTime {
	public static void main(String[] args) {
		// 获取当前的 ZonedDateTime 通过系统默认时区
		ZonedDateTime zdt1 = ZonedDateTime.now();
		System.out.println("当前 ZonedDateTime:" + zdt1);
		LocalDateTime ldt2 = zdt1.toLocalDateTime();
		OffsetDateTime odt = zdt1.toOffsetDateTime();
		Instant i1 = zdt1.toInstant();
		System.out.println("转为LocalDateTime: " + ldt2);
		System.out.println("转为OffsetDateTime: " + odt);
		System.out.println("转为Instant: " + i1);
		// 创建一个 LocalDateTime
		LocalDateTime ldt = LocalDateTime.of(2019, Month.MARCH, 11, 7, 30);

		// 创建美国芝加哥时区的 ZonedDateTime
		ZoneId usCentralZone = ZoneId.of("America/Chicago");
		ZonedDateTime zdt2 = ZonedDateTime.of(ldt, usCentralZone);
		System.out.println(zdt2);

		// 获取 Offset 跟 Zone ID
		ZoneOffset offset = zdt2.getOffset();
		ZoneId zone = zdt2.getZone();
		System.out.println("Offset:" + offset + ", Zone:" + zone);

		// 减去 10 小时.
		ZonedDateTime zdt3 = zdt2.minusHours(10);
		System.out.println(zdt3);

	}
}
